# coding=UTF-8
from django.http import HttpResponse
from django.shortcuts import render_to_response
from zhongsou.jd.JdApi import execute as jdExec
from zhongsou.dd.DdApi import execute as ddExec
import json

# Create your views here.


def index(request):

    return render_to_response('zhongsou/index.html', {
        'name': 'liyc'
    })


def jdIndex(request):

    return render_to_response('zhongsou/jd_index.html', {
        'title': '京东商品API'
    })


def ddIndex(request):

    return render_to_response('zhongsou/dd_index.html', {
        'title': '当当商品API'
    })


def jdApi(request):

    method = request.GET['m']
    param = request.GET['p']

    if not param:
        param = '{}'

    try:
        json.loads(param)
    except:
        return HttpResponse('输入参数格式不正确！（json格式）')

    result = jdExec(method, param)
    return HttpResponse(result)


def ddApi(request):

    result = ddExec()
    return HttpResponse(result)
